package by.airlanterns.service;

import by.airlanterns.dao.CategoryDaoImpl;
import by.airlanterns.dto.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Sergey
 * Date: 27.01.13
 * Time: 17:18
 * To change this template use File | Settings | File Templates.
 */
@Service
public class CategoryService {
    @Autowired
    private CategoryDaoImpl categoryDao;

    public void saveOrUpdate(Category category) {
        categoryDao.saveOrUpdate(category);
    }

    public Category findCategoryById(int id) {
        return categoryDao.findById(id);
    }

    public List<Category> getAllCategories() {
        return categoryDao.findAll();
    }

    public Category findCategoryByTitle(String title) {
        List<Category> list = categoryDao.findCategoryByTitle(title);
        if (list.size() != 0) {
            return list.get(0);
        }
        return new Category();
    }


}
